
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        width: 100px;
        height: 100px;
        background-color: red;
        /* transform: translate(500px, 0px); */
      }
    </style>
  </head>
  <body>
    <div class="box"></div>
  </body>
  <script>
    let box = document.querySelector(".box");
    console.log(box);
    function fn1(box) {
      //返回一个个 Promise实例对象
      return new Promise((resolve) => {
        setTimeout(() => {
          box.style.transform = " translate(500px,0px)";
          resolve();
        }, 1000);
      });
    }
    function fn2(box) {
      return new Promise((resolve) => {
        setTimeout(() => {
          box.style.transform = " translate(500px,500px)";
          resolve();
        }, 1000);
      });
    }
    function fn3(box) {
      return new Promise((resolve) => {
        setTimeout(() => {
          box.style.transform = "translate(0px, 500px)";
          resolve();
        }, 1000);
      });
    }
    function fn4(box) {
      return new Promise((resolve) => {
        setTimeout(() => {
          box.style.transform = "translate(0px,0px)";
          resolve();
        }, 1000);
      });
    }

    fn1(box)
      .then(() => {
        //返回fn2(box)调用完的结果,也就是一个Promise的实例
        return fn2(box);
      })
      .then(() => {
        return fn3(box);
      })
      .then(() => {
        fn4(box);
      });
  </script>
</html>
